<template>
  <el-container>
    <el-header>
      <el-row type="flex">
        <el-col :span="20"
          ><div class="grid-content bg-purple title" style="text-align: left">
            <h1>电商后台管理系统</h1>
          </div></el-col
        >
        <el-col :span="2"
          ><div class="grid-content bg-purple-light" style="text-align: right">
            {{ getUsername }}
          </div></el-col
        >
        <el-col :span="2"
          ><div class="grid-content bg-purple" style="text-align: right">
            <el-button type="info" @click="logout">退出</el-button>
          </div></el-col
        >
      </el-row>
    </el-header>
    <el-container>
      <el-aside width="200px">
        <left-menu></left-menu>
      </el-aside>
      <el-container>
        <router-view></router-view>
      </el-container>
    </el-container>
  </el-container>
</template>

<script>
import leftMenu from "../../components/leftMenu.vue";

import { mapGetters } from "vuex";

export default {
  components: { leftMenu },
  computed: {
    ...mapGetters(["getUsername"]),
  },
  methods: {
    myMessage(type, text) {
      this.$message({
        type: type,
        message: text,
      });
    },
    async logout() {
      //  1 点击的提示用户是否真的要退出  如果是否 那么什么都不做
      // 如果是 真的要退出   发送 退出请求的接口 如果真的退出了 那么 跳转到登录页面
      // 并且清空本地缓存的的 username

      let res = await this.$confirm("此操作会退出登录, 是否继续?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).catch(()=>{}) // 这里的取消必须加上一个catch 的回调函数
      if (res != "confirm") return this.myMessage("info", "取消");
      this.myMessage("success", "退出成功");
      this.$store.commit("clearToken");
      this.$router.replace({ path: "/login" });
    },
  },
};
</script>

<style scoped>
.el-header,
.el-footer {
  background-color: #333333;
  color: #ffffff;
  text-align: center;
  line-height: 60px;
}
.el-container{
  height: 100%;
}
.el-aside {
  /* background-color: #d3dce6; */
  height: 100%;
  background: #333333;
  color: #333;
  text-align: center;
  line-height: 200px;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
  text-align: center;
  line-height: 160px;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}

.title {
  font-size: 20px;
  font-weight: 900;
  text-align: left;
}
</style>
